package study.core.rdd.operator

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * 转换算子之distinct操作
 * 将数据集中重复的数据去重
 *
 * @author zh
 * @date 2021/5/15 10:47
 */
object TestDistinct {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("rddMap")
    val context = new SparkContext(sparkConf)

    // 准备集合
    val list = List(1, 2, 3, 4, 5, 4, 2)
    // 创建RDD
    val rdd: RDD[Int] = context.makeRDD(list, 2)

    // 去重
    val result = rdd.distinct()

    result.collect().foreach(println)

    context.stop()

    //4
    //2
    //1
    //3
    //5

  }

}
